package com.iplant.aps.service.po.mrp;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.aps.service.po.aps.APSTaskPart;
import com.iplant.aps.service.po.aps.APSTaskPartPoint;
import com.iplant.aps.service.po.oms.OMSOrder;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.pdm.service.po.mss.MSSBOMItem;

import java.io.Serializable;
import java.util.Calendar;

/**
 * 物料需求计划
 *
 * @author YouWang·Peng
 * @CreateTime 2022-3-8 11:02:07
 */

@DBBasePO(TableName = "mrp_material_item", Schemas = DBSchemas.APS, Name = false, Active = false,
        CheckName = {"Code", "OrderID,MaterialID,RoutePartID,RoutePartPointID,DemandDate",
                "PlanID,RoutePartID,RoutePartPointID,DemandDate"},
        CodeAuto = true, CodePrefix = "MRPI-{yyMMdd}-")
public class MRPMaterialItem extends BasePO implements Serializable {
    /**
     * 序列号
     */
    private static final long serialVersionUID = 1L;

    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int PlanID = 0;

    /**
     * 工厂ID
     */
    @DBCondition
    @DBField
    public int FactoryID = 0;
    /**
     * 工厂名称
     */
    @DBJoin(name = "Name", tableName = "fmc_factory", tableAsName = "fmc_factory1", Schemas = DBSchemas.Basic,
            MainTableField = "FactoryID")
    public String FactoryName = "";
    /**
     * 工厂编码
     */
    @DBJoin(name = "Code", tableName = "fmc_factory", tableAsName = "fmc_factory1", Schemas = DBSchemas.Basic,
            MainTableField = "FactoryID")
    public String FactoryCode = "";

    /**
     * 车型ID
     */
    @DBCondition
    @DBField(CheckValue = true)
    public int ProductID = 0;
    @DBJoin(name = "Code", tableName = "fpc_product", tableAsName = "fpc_product1", Schemas = DBSchemas.PDM,
            MainTableField = "ProductID")
    public String ProductCode = "";

    @DBJoin(name = "Name", tableName = "fpc_product", tableAsName = "fpc_product1", Schemas = DBSchemas.PDM,
            MainTableField = "ProductID")
    public String ProductName = "";

    @DBCondition
    @DBField(CheckValue = true)
    public int LineID = 0;

    @DBJoin(name = "Name", tableName = "fmc_line", tableAsName = "l1", Schemas = DBSchemas.PDM,
            MainTableField = "LineID")
    public String LineName = "";

    @DBJoin(name = "Code", tableName = "fmc_line", tableAsName = "l1", Schemas = DBSchemas.PDM,
            MainTableField = "LineID")
    public String LineCode = "";

    @DBCondition
    @DBField
    public int CustomerID = 0;
    /**
     * 客户名称
     */
    @DBJoin(name = "Name", tableName = "crm_customer", tableAsName = "crm_customer1", Schemas = DBSchemas.Basic,
            MainTableField = "CustomerID")
    public String CustomerName = "";
    /**
     * 客户编码
     */
    @DBJoin(name = "Code", tableName = "crm_customer", tableAsName = "crm_customer1", Schemas = DBSchemas.Basic,
            MainTableField = "CustomerID")
    public String CustomerCode = "";


    /**
     * 订单ID
     */
    @DBCondition
    @DBField
    public int OrderID = 0;

    @DBCondition
    @DBJoin(name = "Code", tableName = "oms_order", tableAsName = "oms1", Schemas = DBSchemas.APS,
            MainTableField = "OrderID")
    public String OrderNo = "";


    /**
     * 工件号（广机：车号）
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "PartNo", tableName = "oms_order", tableAsName = "oms1", Schemas = DBSchemas.APS,
            MainTableField = "OrderID")
    public String PartNo = "";


    /**
     * 项目号
     */
    @DBCondition
    @DBJoin(name = "WBSNo", tableName = "oms_order", tableAsName = "oms1", Schemas = DBSchemas.APS,
            MainTableField = "OrderID")
    public String WBSNo = "";


    /**
     * 工艺ID
     */
    @DBCondition
    @DBField
    public int RoutePartID = 0;
    /**
     * 工位名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public String RoutePartName = "";


    /**
     * 工序ID
     */
    @DBCondition
    @DBField
    public int RoutePartPointID = 0;
    /**
     * 工序名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fpc_routepartpoint", tableAsName = "fpc_routepartpoint1", Schemas =
            DBSchemas.PDM,
            MainTableField = "RoutePartPointID")
    public String RoutePartPointName = "";

    /**
     * 物料ID
     */
    @DBCondition
    @DBField
    public int MaterialID = 0;
    /**
     * 物料编码
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "mss_material", tableAsName = "m2", Schemas = DBSchemas.Basic,
            MainTableField = "MaterialID")
    public String MaterialCode = "";

    /**
     * 物料名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "MaterialName", tableName = "mss_material", tableAsName = "m2", Schemas = DBSchemas.Basic,
            MainTableField = "MaterialID")
    public String MaterialName = "";
    /**
     * 物料类型ID
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "MaterialTypeID", tableName = "mss_material", tableAsName = "m2", Schemas = DBSchemas.Basic,
            MainTableField = "MaterialID")
    public int MaterialTypeID = 0;


    @DBCondition
    @DBJoin(name = "MaterialGroupID", tableName = "mss_material", tableAsName = "m2", JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, MainTableField = "MaterialID")
    public int MaterialGroupID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "mss_materialgroup", tableAsName = "m1",
            JoinIndex = 3, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialGroupID=m1.ID")
    public String MaterialGroupCode = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "mss_materialgroup", tableAsName = "m1",
            JoinIndex = 3, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialGroupID=m1.ID")
    public String MaterialGroupName = "";


    @DBCondition(CompareType = DBCondition.DBCompareType.leftLike)
    @DBJoin(name = "FullGroupName", tableName = "mss_materialgroup", tableAsName = "m1",
            JoinIndex = 3, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialGroupID=m1.ID")
    public String MaterialFullGroup = "";

    /**
     * 物料类型名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "mss_materialtype", tableAsName = "mt1",
            JoinIndex = 4, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialTypeID=mt1.ID")
    public String MaterialTypeName = "";

    /**
     * 物料类型名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "mss_materialtype", tableAsName = "mt1",
            JoinIndex = 4, JoinMode = DBJoin.DBJoinMode.Inner,
            Schemas = DBSchemas.Basic, ConditionalJoin = "m2.MaterialTypeID=mt1.ID")
    public String MaterialTypeCode = "";
    /**
     * 需求数量
     */
    @DBField
    public double PlanFQTY = 0.0;


    /**
     * 定额物料数
     */
    @DBField
    public double StandardNum = 0.0f;


    /**
     * 当日计划数
     */
    @DBField
    public double OrderPlan = 0.0f;


    /**
     * 需求日期
     */
    @DBField
    public Calendar DemandDate = Calendar.getInstance();


    public MRPMaterialItem() {

        super();
    }

    public MRPMaterialItem(OMSOrder wOMSOrder, Calendar wDemandDate,
                           APSTaskPartPoint wAPSTaskPartPoint, MSSBOMItem wMSSBOMItem, double wPlanNum) {
        super();
        DemandDate = wDemandDate;

        FactoryID = wOMSOrder.FactoryID;
        FactoryName = wOMSOrder.FactoryName;
        FactoryCode = wOMSOrder.FactoryCode;
        ProductID = wOMSOrder.ProductID;
        ProductCode = wOMSOrder.ProductCode;
        ProductName = wOMSOrder.ProductName;
        LineID = wOMSOrder.LineID;
        LineName = wOMSOrder.LineName;
        LineCode = wOMSOrder.LineCode;
        CustomerID = wOMSOrder.CustomerID;
        CustomerName = wOMSOrder.CustomerName;
        CustomerCode = wOMSOrder.CustomerCode;
        OrderID = wOMSOrder.ID;
        OrderNo = wOMSOrder.Code;
        PartNo = wOMSOrder.PartNo;

        RoutePartID = wAPSTaskPartPoint.RoutePartID;
        RoutePartName = wAPSTaskPartPoint.RoutePartName;
        RoutePartPointID = wAPSTaskPartPoint.RoutePartPointID;
        RoutePartPointName = wAPSTaskPartPoint.RoutePartPointName;

        MaterialID = wMSSBOMItem.MaterialID;
        MaterialName = wMSSBOMItem.MaterialName;
        MaterialCode = wMSSBOMItem.MaterialNo;
        MaterialTypeID = wMSSBOMItem.MaterialTypeID;
        MaterialTypeName = wMSSBOMItem.MaterialTypeName;
        MaterialTypeCode = wMSSBOMItem.MaterialTypeCode;
        MaterialGroupID = wMSSBOMItem.MaterialGroupID;
        MaterialGroupCode = wMSSBOMItem.MaterialGroupCode;
        MaterialGroupName = wMSSBOMItem.MaterialGroupName;
        MaterialFullGroup = wMSSBOMItem.MaterialFullGroup;
        OrderPlan = wPlanNum;
        StandardNum = wMSSBOMItem.MaterialNumber;
        if (StandardNum <= 0)
            StandardNum = 1;
        PlanFQTY = OrderPlan * StandardNum;

    }

    public MRPMaterialItem(OMSOrder wOMSOrder, Calendar wDemandDate,
                           APSTaskPart wAPSTaskPart, MSSBOMItem wMSSBOMItem, float wPlanNum) {
        super();
        DemandDate = wDemandDate;

        FactoryID = wOMSOrder.FactoryID;
        FactoryName = wOMSOrder.FactoryName;
        FactoryCode = wOMSOrder.FactoryCode;
        ProductID = wOMSOrder.ProductID;
        ProductCode = wOMSOrder.ProductCode;
        ProductName = wOMSOrder.ProductName;
        LineID = wOMSOrder.LineID;
        LineName = wOMSOrder.LineName;
        LineCode = wOMSOrder.LineCode;
        CustomerID = wOMSOrder.CustomerID;
        CustomerName = wOMSOrder.CustomerName;
        CustomerCode = wOMSOrder.CustomerCode;
        OrderID = wOMSOrder.ID;
        OrderNo = wOMSOrder.Code;
        PartNo = wOMSOrder.PartNo;

        RoutePartID = wAPSTaskPart.RoutePartID;
        RoutePartName = wAPSTaskPart.RoutePartName;
        RoutePartPointID = 0;
        RoutePartPointName = "";

        MaterialID = wMSSBOMItem.MaterialID;
        MaterialName = wMSSBOMItem.MaterialName;
        MaterialCode = wMSSBOMItem.MaterialNo;
        MaterialTypeID = wMSSBOMItem.MaterialTypeID;
        MaterialTypeName = wMSSBOMItem.MaterialTypeName;
        MaterialTypeCode = wMSSBOMItem.MaterialTypeCode;
        MaterialGroupID = wMSSBOMItem.MaterialGroupID;
        MaterialGroupCode = wMSSBOMItem.MaterialGroupCode;
        MaterialGroupName = wMSSBOMItem.MaterialGroupName;
        MaterialFullGroup = wMSSBOMItem.MaterialFullGroup;
        OrderPlan = wPlanNum;
        StandardNum = wMSSBOMItem.MaterialNumber;
        if (StandardNum <= 0)
            StandardNum = 1;
        PlanFQTY = OrderPlan * StandardNum;

    }

    public MRPMaterialItem(MRPMaterialPlan wMRPMaterialPlan, Calendar wDemandDate,
                           APSTaskPartPoint wAPSTaskPartPoint, MSSBOMItem wMSSBOMItem, float wPlanNum) {
        super();
        DemandDate = wDemandDate;

        FactoryID = wMRPMaterialPlan.FactoryID;
        FactoryName = wMRPMaterialPlan.FactoryName;
        FactoryCode = wMRPMaterialPlan.FactoryCode;
        ProductID = wMRPMaterialPlan.ProductID;
        ProductCode = wMRPMaterialPlan.ProductCode;
        ProductName = wMRPMaterialPlan.ProductName;
        LineID = wMRPMaterialPlan.LineID;
        LineName = wMRPMaterialPlan.LineName;
        LineCode = wMRPMaterialPlan.LineCode;
        CustomerID = wMRPMaterialPlan.CustomerID;
        CustomerName = wMRPMaterialPlan.CustomerName;
        CustomerCode = wMRPMaterialPlan.CustomerCode;
        OrderID = wMRPMaterialPlan.OrderID;
        OrderNo = wMRPMaterialPlan.OrderNo;
        PartNo = wMRPMaterialPlan.PartNo;

        RoutePartID = wAPSTaskPartPoint.RoutePartID;
        RoutePartName = wAPSTaskPartPoint.RoutePartName;
        RoutePartPointID = wAPSTaskPartPoint.RoutePartPointID;
        RoutePartPointName = wAPSTaskPartPoint.RoutePartPointName;

        MaterialID = wMSSBOMItem.MaterialID;
        MaterialName = wMSSBOMItem.MaterialName;
        MaterialCode = wMSSBOMItem.MaterialNo;
        MaterialTypeID = wMSSBOMItem.MaterialTypeID;
        MaterialTypeName = wMSSBOMItem.MaterialTypeName;
        MaterialTypeCode = wMSSBOMItem.MaterialTypeCode;
        MaterialGroupID = wMSSBOMItem.MaterialGroupID;
        MaterialGroupCode = wMSSBOMItem.MaterialGroupCode;
        MaterialGroupName = wMSSBOMItem.MaterialGroupName;
        MaterialFullGroup = wMSSBOMItem.MaterialFullGroup;
        OrderPlan = wPlanNum;
        StandardNum = wMSSBOMItem.MaterialNumber;
        if (StandardNum <= 0)
            StandardNum = 1;
        PlanFQTY = OrderPlan * StandardNum;

    }



    @JsonProperty("FactoryID")
    public int getFactoryID() {
        return FactoryID;
    }

    public void setFactoryID(int factoryID) {
        FactoryID = factoryID;
    }

    @JsonProperty("FactoryName")
    public String getFactoryName() {
        return FactoryName;
    }

    public void setFactoryName(String factoryName) {
        FactoryName = factoryName;
    }

    @JsonProperty("FactoryCode")
    public String getFactoryCode() {
        return FactoryCode;
    }

    public void setFactoryCode(String factoryCode) {
        FactoryCode = factoryCode;
    }


    @JsonProperty("MaterialID")
    public int getMaterialID() {
        return MaterialID;
    }

    public void setMaterialID(int materialID) {
        MaterialID = materialID;
    }

    @JsonProperty("MaterialCode")
    public String getMaterialCode() {
        return MaterialCode;
    }

    public void setMaterialCode(String materialCode) {
        MaterialCode = materialCode;
    }

    @JsonProperty("MaterialName")
    public String getMaterialName() {
        return MaterialName;
    }

    public void setMaterialName(String materialName) {
        MaterialName = materialName;
    }

    @JsonProperty("MaterialTypeID")
    public int getMaterialTypeID() {
        return MaterialTypeID;
    }

    public void setMaterialTypeID(int materialTypeID) {
        MaterialTypeID = materialTypeID;
    }

    @JsonProperty("MaterialGroupID")
    public int getMaterialGroupID() {
        return MaterialGroupID;
    }

    public void setMaterialGroupID(int materialGroupID) {
        MaterialGroupID = materialGroupID;
    }

    @JsonProperty("MaterialGroupCode")
    public String getMaterialGroupCode() {
        return MaterialGroupCode;
    }

    public void setMaterialGroupCode(String materialGroupCode) {
        MaterialGroupCode = materialGroupCode;
    }

    @JsonProperty("MaterialGroupName")
    public String getMaterialGroupName() {
        return MaterialGroupName;
    }

    public void setMaterialGroupName(String materialGroupName) {
        MaterialGroupName = materialGroupName;
    }

    @JsonProperty("MaterialFullGroup")
    public String getMaterialFullGroup() {
        return MaterialFullGroup;
    }

    public void setMaterialFullGroup(String materialFullGroup) {
        MaterialFullGroup = materialFullGroup;
    }

    @JsonProperty("MaterialTypeName")
    public String getMaterialTypeName() {
        return MaterialTypeName;
    }

    public void setMaterialTypeName(String materialTypeName) {
        MaterialTypeName = materialTypeName;
    }

    @JsonProperty("MaterialTypeCode")
    public String getMaterialTypeCode() {
        return MaterialTypeCode;
    }

    public void setMaterialTypeCode(String materialTypeCode) {
        MaterialTypeCode = materialTypeCode;
    }

    @JsonProperty("DemandDate")
    public Calendar getDemandDate() {
        return DemandDate;
    }

    public void setDemandDate(Calendar demandDate) {
        DemandDate = demandDate;
    }


    @JsonProperty("PlanID")
    public int getPlanID() {
        return PlanID;
    }

    public void setPlanID(int planID) {
        PlanID = planID;
    }

    @JsonProperty("ProductID")
    public int getProductID() {
        return ProductID;
    }

    public void setProductID(int productID) {
        ProductID = productID;
    }

    @JsonProperty("ProductCode")
    public String getProductCode() {
        return ProductCode;
    }

    public void setProductCode(String productCode) {
        ProductCode = productCode;
    }

    @JsonProperty("ProductName")
    public String getProductName() {
        return ProductName;
    }

    public void setProductName(String productName) {
        ProductName = productName;
    }

    @JsonProperty("LineID")
    public int getLineID() {
        return LineID;
    }

    public void setLineID(int lineID) {
        LineID = lineID;
    }

    @JsonProperty("LineName")
    public String getLineName() {
        return LineName;
    }

    public void setLineName(String lineName) {
        LineName = lineName;
    }

    @JsonProperty("LineCode")
    public String getLineCode() {
        return LineCode;
    }

    public void setLineCode(String lineCode) {
        LineCode = lineCode;
    }

    @JsonProperty("CustomerID")
    public int getCustomerID() {
        return CustomerID;
    }

    public void setCustomerID(int customerID) {
        CustomerID = customerID;
    }

    @JsonProperty("CustomerName")
    public String getCustomerName() {
        return CustomerName;
    }

    public void setCustomerName(String customerName) {
        CustomerName = customerName;
    }

    @JsonProperty("CustomerCode")
    public String getCustomerCode() {
        return CustomerCode;
    }

    public void setCustomerCode(String customerCode) {
        CustomerCode = customerCode;
    }

    @JsonProperty("OrderID")
    public int getOrderID() {
        return OrderID;
    }

    public void setOrderID(int orderID) {
        OrderID = orderID;
    }

    @JsonProperty("OrderNo")
    public String getOrderNo() {
        return OrderNo;
    }

    public void setOrderNo(String orderNo) {
        OrderNo = orderNo;
    }

    @JsonProperty("PartNo")
    public String getPartNo() {
        return PartNo;
    }

    public void setPartNo(String partNo) {
        PartNo = partNo;
    }

    @JsonProperty("WBSNo")
    public String getWBSNo() {
        return WBSNo;
    }

    public void setWBSNo(String WBSNo) {
        this.WBSNo = WBSNo;
    }

    @JsonProperty("RoutePartID")
    public int getRoutePartID() {
        return RoutePartID;
    }

    public void setRoutePartID(int routePartID) {
        RoutePartID = routePartID;
    }

    @JsonProperty("RoutePartName")
    public String getRoutePartName() {
        return RoutePartName;
    }

    public void setRoutePartName(String routePartName) {
        RoutePartName = routePartName;
    }

    @JsonProperty("RoutePartPointID")
    public int getRoutePartPointID() {
        return RoutePartPointID;
    }

    public void setRoutePartPointID(int routePartPointID) {
        RoutePartPointID = routePartPointID;
    }

    @JsonProperty("RoutePartPointName")
    public String getRoutePartPointName() {
        return RoutePartPointName;
    }

    public void setRoutePartPointName(String routePartPointName) {
        RoutePartPointName = routePartPointName;
    }

    @JsonProperty("PlanFQTY")
    public double getPlanFQTY() {
        return PlanFQTY;
    }

    public void setPlanFQTY(double planFQTY) {
        PlanFQTY = planFQTY;
    }

    @JsonProperty("StandardNum")
    public double getStandardNum() {
        return StandardNum;
    }

    public void setStandardNum(double standardNum) {
        StandardNum = standardNum;
    }

    @JsonProperty("OrderPlan")
    public double getOrderPlan() {
        return OrderPlan;
    }

    public void setOrderPlan(double orderPlan) {
        OrderPlan = orderPlan;
    }
}
